package com.atguigu.cloud.controller;


import com.atguigu.cloud.entities.Pay;
import com.atguigu.cloud.service.PayService0718;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.Random;


@RestController
@Slf4j
public class CustomerController {
    @Resource private PayService0718 customerService;

    @RequestMapping(value = "/customer/add",method = RequestMethod.POST)
    public void addCustomer() {
        for (int i = 0; i < 2; i++) {
            Pay customer = new Pay();

            customer.setPayNo("customer" + i);
            customer.setUserId(new Random().nextInt(30)+1);
            customer.setPayNo("138xxxxxxxx");
            customer.setDeleted((byte)new Random().nextInt(2));
            customer.setUpdateTime(Date.from(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant()));
        }
    }


    @RequestMapping(value = "/customer/{id}",method = RequestMethod.GET)
    public Pay findCustomerById(@PathVariable Integer customerId) {
        return customerService.findCustomerById(customerId);
    }
}
